package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.domain.MemberVO;
import com.macro.mall.portal.service.UmsMemberService;
import com.macro.mall.portal.service.VersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@Api(tags = "RestLoginController", description = "一键登录Controller")
@RequestMapping("RestLoginController")
public class RestLoginController {

    @Autowired
    private UmsMemberService memberService;
    @Autowired
    private VersionService versionService;

    @ApiOperation(value = "一键登录")
    @GetMapping("/doLogin")
    public CommonResult doLogin(@ApiParam(value = "token") @RequestParam String token) {
        Map<String, Object> stringObjectMap = memberService.doLogin(token);
        return CommonResult.success(stringObjectMap);
    }

    @ApiOperation("一键注册登录")
    @RequestMapping(value = "/doBindLogin", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult bindWeChat(@ApiParam(value = "请求报文") @RequestBody MemberVO request) {
        Map<String, Object> register = memberService.doBindLogin(request);
        return CommonResult.success(register);
    }

    @ApiOperation(value = "检测升级")
    @GetMapping("/update")
    public CommonResult update(@ApiParam(value = "name") @RequestParam String name, @ApiParam(value = "version")@RequestParam String version) {
        Map<String, Object> update = versionService.update(name,version);
        return CommonResult.success(update);
    }
}
